/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.client.view.boat;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import gwtupload.client.MultiUploader;
import org.lucava.boatskeeper.client.presenter.boat.EditBoatPresenter;

/**
 *
 * @author glenn
 */
public class EditBoatView extends Composite implements EditBoatPresenter.Display {

    private final TextBox displayName;
    private final ListBox categoryBox;
    private final FlexTable detailsTable;
    private final Button saveButton;
    private final Button cancelButton;
    private final MultiUploader defaultUploader;
    private Panel imagePanel;

    public EditBoatView() {

        imagePanel = new SimplePanel();
        
        DecoratorPanel contentDetailsDecorator = new DecoratorPanel();
        contentDetailsDecorator.setWidth("40em");
        initWidget(contentDetailsDecorator);

        VerticalPanel contentDetailsPanel = new VerticalPanel();
        contentDetailsPanel.setWidth("100%");

        // Create the boats list
        //
        detailsTable = new FlexTable();
        detailsTable.setCellSpacing(0);
        detailsTable.setWidth("100%");
        detailsTable.addStyleName("boats-ListContainer");
        detailsTable.getColumnFormatter().addStyleName(1, "add-boat-input");
        displayName = new TextBox();

        categoryBox = new ListBox();

        defaultUploader = new MultiUploader();
        defaultUploader.setMaximumFiles(1);

        initDetailsTable();
        contentDetailsPanel.add(detailsTable);

        HorizontalPanel menuPanel = new HorizontalPanel();
        saveButton = new Button("Save");
        cancelButton = new Button("Cancel");
        menuPanel.add(saveButton);
        menuPanel.add(cancelButton);
        contentDetailsPanel.add(menuPanel);
        contentDetailsDecorator.add(contentDetailsPanel);
    }

    private void initDetailsTable() {
        detailsTable.setWidget(0, 0, new Label("Nom"));
        detailsTable.setWidget(0, 1, displayName);
        detailsTable.setWidget(1, 0, new Label("Catégorie"));
        detailsTable.setWidget(1, 1, categoryBox);
        detailsTable.setWidget(2, 0, new Label("Aperçu"));
        detailsTable.setWidget(2, 1, imagePanel);
        detailsTable.setWidget(3, 0, new Label("Image"));
        detailsTable.setWidget(3, 1, defaultUploader);
        displayName.setFocus(true);
    }

    @Override
    public HasClickHandlers getCancelButton() {
        return cancelButton;
    }

    @Override
    public HasValue<String> getDisplayName() {
        return displayName;
    }

    @Override
    public MultiUploader getUploader() {
        return defaultUploader;
    }

    @Override
    public Integer getCategoryValue() {
        return Integer.parseInt(categoryBox.getValue(categoryBox.getSelectedIndex()));
    }

    @Override
    public ListBox getCategoryList() {
        return categoryBox;
    }

    @Override
    public HasClickHandlers getSaveButton() {
        return saveButton;
    }
    
    @Override
    public Panel getImagePanel() {
        return this.imagePanel;
    }

    @Override
    public Widget asWidget() {
        return this;
    }

    @Override
    public void startProcessing() {
    }

    @Override
    public void stopProcessing() {
    }

    
}
